function prob_vec = changepoints(data,lower_freq,higher_freq,length_g)

% function prob_vec = changepoints(data,parameter_matrix)
% 'convoles' (using neat bayesian result for marginal posterior prob) the parameter matrix with the data.
profile on

g_up = parameter_matrix(100,50,8000,lower_freq,higher_freq);
g_down = parameter_matrix(100,50,8000,higher_freq,lower_freq);
g_low = parameter_matrix(100,50,8000,lower_freq,lower_freq);
g_high = parameter_matrix(100,50,8000,higher_freq,higher_freq);

prob_vec = zeros((length(data) - length_g) + 1,1);
prob_vec(1) = 0;
for m = 1:(length(data) - length_g)
	step_up(m) = marginal_posterior_probability( data( m:(m+(length_g-1)) ), g_up );
	step_down(m) = marginal_posterior_probability( data( m:(m+(length_g-1)) ), g_down);
    stay_high(m) = marginal_posterior_probability( data( m:(m+(length_g-1)) ), g_high);
	stay_low(m) = marginal_posterior_probability( data( m:(m+(length_g-1)) ), g_low );
	
	if ((step_up(m) >= step_down(m)) && (step_up(m) >= stay_high(m)) && (step_up(m) >= stay_low(m)))
		prob_vec(m+1) = prob_vec(m+1) + 1;
	elseif ((step_down(m) >= stay_high(m)) && (step_down(m) >= stay_low(m))	)
		prob_vec(m+1) = prob_vec(m+1) - 1;
	elseif ((stay_high(m) >= stay_low(m)))
		prob_vec(m+1) = prob_vec(m+1) + 0;
	else
		prob_vec(m+1) = prob_vec(m+1) + 0;
	end
	
end

profile off

close all
figure(); plot(prob_vec), title('Changepoint locations')
figure(); plot(step_up), title('step up')
figure(); plot(step_down), title('step down')
figure(); plot(stay_high), title('stay high')
figure(); plot(stay_low), title('stay low')
profile viewer


	